const express = require('express')
const router = express.Router()
const userDao = require('../database/userDao')
// 根据账号密码获取用户
router.post('/getUser',async (req,res) => {
  let { user_account,user_pwd } = req.body
  try{
    let result = await userDao.getUser( user_account,user_pwd )
    res.send({
      code:200,
      msg:'获取成功',
      data:result
    })
  }catch(err){
    res.send({
      code:400,
      msg:'获取失败',
      data:err
    })
  }
})
// 新增用户 输入用户账号密码与名称
router.put('/addUser',async (req,res) => {
  let { user_name,user_account,user_pwd } = req.body
  try{
    let result = await userDao.addUser( user_name,user_account,user_pwd )
    res.send({
      code:200,
      msg:'获取成功',
      data:result
    })
  }catch(err){
    res.send({
      code:400,
      msg:'获取失败',
      data:err
    })
  }
})
// 根据用户id获取用户信息
router.get('/findUser',async(req,res) => {
  let id = req.query.id
  try{
    let result = await userDao.findUser(id)
    res.send({
      code:200,
      msg:'获取成功',
      data:result
    })
  }catch(err){
    res.send({
      code:400,
      msg:'获取失败',
      data:err
    })
  }
})

module.exports = router